<?php
/**
 * 会员提现控制器
 * @author maniac
 */
namespace app\manage\controller;

use app\common\model\MemberCashLog;
use app\common\service\Balance as BalanceService;

class MemberCash extends Base
{
    public function index(){
        $data = MemberCashLog::order('status')->paginate(10);
        return view('',[
            'data'  => $data,
            'count' => $data->total(),
            'page'  => $data->currentPage(),
            'limit' => $data->listRows(),
        ]);
    }
    public function examine(){
        $id = input('id');
        $status = input('status');
        $data = MemberCashLog::get($id);
        $data->status = $status;
        $data->exam_time = time();
        if ($data->save()){
            if((new BalanceService())::saveBalanceLog($id,'-'.$data->money,1,"提现",$data->business_id)){
                (new BalanceService())::retryBalance($id);
            }
            return j(0,'操作成功');
        }else{
            return j(1,'操作失败');
        }
    }
    public function show(){
        $id = input('id');
        $data = MemberCashLog::with('member_cash')->get($id);
        return view('/cash_show',[
            'data' => $data
        ]);
    }
}
